﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.ComponentModel.DataAnnotations;
using System.Data.Linq;
using System.Data.Linq.Mapping;
using System.Linq;
using System.Text;
using Chowpoo.Sql;

namespace CourseSystem.Core.Entities
{
    [Table(Name = "Chapter")]
    public class ChapterInfo : IDetach
    {
        public ChapterInfo()
        {
            Detach();
        }
        #region Model
        private int _id;
        private string _name;
        private byte _orderid = 255;

        private EntitySet<SectionInfo> _sectionInfo;
        [System.Data.Linq.Mapping.Association(Storage = "_sectionInfo", ThisKey = "Id", OtherKey = "ChapterId")]
        public EntitySet<SectionInfo> SectionInfo
        {
            get { return this._sectionInfo; }
            set { this._sectionInfo.Assign(value); }
        }

        /// <summary>
        /// 
        /// </summary>
        [Column(IsDbGenerated = true, IsPrimaryKey = true, IsVersion = true)]
        public int Id
        {
            set { _id = value; }
            get { return _id; }
        }
        /// <summary>
        /// 
        /// </summary>
        [Column]
        [DisplayName("章名")]
        [Required(ErrorMessage = "必须填写")]
        public string Name
        {
            set { _name = value; }
            get { return _name; }
        }
        /// <summary>
        /// 
        /// </summary>
        [Column]
        [DisplayName("章数")]
        [RangeValidation(Max = 255, Min = 0, ErrorMessage = "章数错误")]
        public byte OrderId
        {
            set { _orderid = value; }
            get { return _orderid; }
        }
        #endregion Model

        public void Detach()
        {
            this._sectionInfo = new EntitySet<SectionInfo>();
        }
    }
}
